from . import spider_bp
from . import Spider_1 as Spider
import os
from multiprocessing import Process

CurrentProcess = None


@spider_bp.route('/start/')
def run_spider():
    global CurrentProcess
    if CurrentProcess is not None:
        return '当前正在运行'

    CurrentProcess = Spider.run()
    return '开始运行'


@spider_bp.route('/stop/')
def stop_spider():
    global CurrentProcess
    if CurrentProcess is not None:
        CurrentProcess.terminate()
        CurrentProcess = None
        # CurrentProcess.close()
    return "已停止"
